home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 June: Reference Library / Dev.CD Jun 94.toast / Periodicals / develop / develop Issue 15 / develop 15 code / Symmetry & Tiles / Tiler Code / TileApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-13  |  5.1 KB  |  234 lines  |  [TEXT/KAHL]

  1. #include     <graphics libraries.h>
  2. #include     <graphics toolbox.h>
  3. #include     <qd library.h>
  4. #include    "AppInterface.h"
  5. #include    "TileProtos.h"
  6. #include    "TileConstants.h"
  7.  
  8. MenuHandle        gAppMenuHandle;
  9. WindowPtr        gWindPtr;
  10.  
  11. //---------------------------------------
  12. //    Tile globals
  13.  
  14. extern Boolean            gContRedraw, gKeepClosed; // State Booleans
  15. extern long                gSymmetry;
  16.  
  17.  
  18. /* Called by the Shell at startup time */
  19. Boolean    AppInit(void)
  20. {
  21.     Boolean AOK;
  22.     
  23.     AOK = TileInit();
  24.     if(AOK && gKeepClosed)
  25.         AttachConstraints();
  26.     return AOK;
  27. }
  28.  
  29. /* Called when the shell receives an Activate event. */
  30. void AppActivate(WindowPtr wind, Boolean activate)
  31. {
  32. }
  33.  
  34. /* Called when a window needs updating. BeginUpdate() has already been called, and the 
  35. port is set to the appropriate window */
  36. void AppUpdate(EventRecord *event)
  37. {
  38.     TileUpdate();
  39. }
  40.  
  41. /* Called when the shell recieves a null event. */
  42. void AppIdle(EventRecord *Event)
  43. {
  44. }
  45.  
  46. /* Called when there is a click in the content of a window. The port is already set to 
  47. the window, and thePt is in local coords. */
  48. void AppClick(Point thePt, WindowPtr wind, Boolean doubleClick, EventRecord *theEvent)
  49. {
  50.     gxPoint        clickPt;
  51.         
  52.     ShortPointToFixed(&thePt, &clickPt);
  53.     
  54.     if(TileClick(&clickPt, theEvent->modifiers & optionKey))
  55.         InvalRect(&wind->portRect);
  56.  
  57. }
  58.  
  59. /* Called when there is a click in the grow region. Just grows the window, resetting 
  60. necessary shapes */
  61. void AppGrowWindow(WindowPtr wind, Point where, Rect *desk)
  62. {
  63.     Rect            limits;
  64.     long            size;
  65.     
  66.     /* Set up size limits */
  67.     limits.top = limits.left = 72; /* One inch minimum */
  68.     
  69.     // Limit to something reasonable
  70.     limits.right = 600;
  71.     limits.bottom = 450;
  72.     
  73.     /* Let the user grow the window */
  74.     size = GrowWindow(wind, where, &limits);
  75.     
  76.     // If the size changed, then size the window
  77.     if(size != 0)
  78.     {
  79.         short    hSize, vSize;
  80.         
  81.         SetPort(wind);
  82.         
  83.         /* OK, size it, but first make sure that the size is within limits (users
  84.         can hold down the command key to bypass the limit, but we won't let 'em). 
  85.         Note that we subtract 1 from the limits to account for the window frame */
  86.         hSize = LoWord(size);
  87.         vSize = HiWord(size);
  88.         if(hSize > limits.right - 1) hSize = limits.right - 1;
  89.         if(vSize > limits.bottom - 1) vSize = limits.bottom - 1;
  90.         
  91.         if(ChangeWindowSize(gWindPtr, hSize, vSize) == true)
  92.             InvalRect(&wind->portRect);
  93.         else
  94.             SysBeep(10);
  95.     }
  96. }
  97.  
  98. /* Called when the user clicks in the zoom box of a window. */
  99. void     AppZoomWindow(WindowPtr wind, short zoomDir)
  100. {
  101. }
  102.     
  103. /* Called when there is a click in the menu bar, before the menu is shown. This is
  104. the app's opportunity to enable and disable menu items. */
  105. void    AppAdjustMenus()
  106. {
  107.     CheckItem(gAppMenuHandle, iContRedraw, gContRedraw);
  108.     CheckItem(gAppMenuHandle, iConstrain, gKeepClosed);
  109. }    
  110.  
  111. /* called when a menu other than Apple, File, or Edit is used. */
  112. void AppMenu(short id, short item)
  113. {
  114.     if(id == kTileMenuID)
  115.     {
  116.         switch(item)
  117.         {
  118.             case iContRedraw:
  119.                 gContRedraw = !gContRedraw;
  120.                 break;
  121.             
  122.             case iConstrain:
  123.                 gKeepClosed = !gKeepClosed;
  124.                 if(gKeepClosed)
  125.                     AttachConstraints();
  126.                 InvalRect(&gWindPtr->portRect);
  127.                 break;
  128.             
  129.             case iResetTile:
  130.                 DefaultTileAndPattern();
  131.                 InvalRect(&gWindPtr->portRect);
  132.                 break;
  133.             
  134.             // A symmetry group was picked
  135.             default:
  136.                 if(item != gSymmetry)
  137.                 {
  138.                     CheckItem(gAppMenuHandle, gSymmetry, false);
  139.                     ChangeSymmetry(gSymmetry, (long)item);
  140.                     CheckItem(gAppMenuHandle, gSymmetry, true);
  141.                     InvalRect(&gWindPtr->portRect);
  142.                 }
  143.                 break;
  144.         }
  145.     }
  146. }
  147.  
  148.  
  149. // Called when the user selects "New" from the File menu.            
  150. void    AppNew(void)
  151. {
  152.     ShowWindow(gWindPtr);
  153. }
  154.  
  155. /* Called when the user selects "Open" from the File menu. */
  156. void    AppOpen(void)
  157. {
  158.     ShowWindow(gWindPtr);
  159. }
  160.  
  161.  
  162. /* Called when the user selects "Close" from the File menu or clicks the close box 
  163. of a window. */            
  164. Boolean    AppClose(void)
  165. {
  166.     /* returns false if the user cancels the save */
  167.     HideWindow(gWindPtr);
  168.     return true;
  169. }
  170.  
  171. /* Called when the user selects "Save" from the File menu. */
  172. Boolean    AppSave(void)
  173. {
  174.     /* returns false if the user cancels the save */
  175.     return true;
  176. }
  177.  
  178. /* Called when the user selects "Save As..." from the File menu. */
  179. Boolean    AppSaveAs(void)
  180. {
  181.     /* returns false if the user cancels the save */
  182.     return true;
  183. }
  184.  
  185. /* Called when the user selects "Page Setup..." from the File menu. */
  186. void AppPageSetup(void)
  187. {
  188. }
  189.  
  190. /* Called when the user selects "Print..." from the File menu. */
  191. void AppPrint(void)
  192. {
  193. }
  194.  
  195. /* Called when the user selects "Undo" from the Edit menu. */
  196. void AppUndo(void)
  197. {
  198. }
  199.  
  200. /* Called when the user selects "Cut" from the Edit menu. */
  201. void AppCut(void)
  202. {
  203. }
  204.  
  205. /* Called when the user selects "Copy" from the Edit menu. */
  206. OSErr AppCopy(void)
  207. {
  208.     return noErr;
  209. }            
  210.             
  211. /* Called when the user selects "Paste" from the Edit menu. */
  212. void AppPaste(void)
  213. {
  214. }
  215.  
  216. /* Called when the user selects "Clear" from the Edit menu. */
  217. void AppClear(void)
  218. {
  219. }
  220.  
  221. /*     Called when the user chooses "Quit" from the File menu. If the user cancels
  222. the save it returns false, otherwise it returns true and the shell quits */
  223. Boolean AppQuit(void)
  224. {
  225.     /* returns false if the user cancels the save at any point */
  226.     return true;
  227. }
  228.  
  229. /* Called when the shell is about to quit, just deallocates memory. */
  230. void AppCleanUp(void)
  231. {
  232.     TileQuit();
  233. }
  234.